
package util;

import java.security.MessageDigest;

/**
 *
 * @author Nickerson
 */
public class MD5 {
    
    public static String encrypt(String pass) throws Exception {
        
        String result = null;

            // informa o algoritmo de encriptacao
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            // tenasforma a string num array de bytes
            byte[] bsenha = pass.getBytes("UTF-8");

            md5.update(bsenha, 0, bsenha.length);

            byte[] bsenha_ = new byte[16];
            // realiza a criptografia
            md5.digest(bsenha_, 0, 16);


            //convert the byte to hex format method 1
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < bsenha_.length; i++) {
            sb.append(Integer.toString((bsenha_[i] & 0xff) + 0x100, 16).substring(1));
            }

            result = sb.toString();

            return result;
    } // encrypt
    
} // MD5